package chapter5;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description: 检测ISBN-13
 * Date:2021/4/4
 * ***************************************************************
 */
public class exc5_47 {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		
		System.out.print("Enter the first 12 digits of an ISBN-13 as a string:  ");
		String s=input.next();
		
		if(s.length()!=12) {
			System.out.print(s+" is an invalid input.");
			System.exit(1);
		}
		
		int sum=0;
		for(int i=0;i<12;i++) {
			int tmp=s.charAt(i)-'0';
			//条件表达式练习，可读性差了点
			sum+=(i%2==1)?(3*tmp):tmp;
		}
		int d=10-sum%10;
		
		int tail=0;
		if(d!=10) {
			tail=d;
		}
		
		System.out.print("The ISBN-13 number is "+s+tail);
		
	}

}
